package com.heima.xxljob.handle;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 你好处理
 *
 * @author DiXiaoNie
 * @date 2023/01/06
 * @since 2023/1/6 10:57
 */
@Component
public class HelloHandle {

/*    @XxlJob(value = "job-handle-398")
    public void helloText() {
        System.out.println("定时器执行了" + new Date());
    }*/


    @XxlJob(value = "job-handle-398")
    public void shardingJobHandler(){
        //分片的参数
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();

        //业务逻辑
        List<Integer> list = getList();
        for (Integer integer : list) {
            if(integer % shardTotal == shardIndex){
                System.out.println("当前第"+shardIndex+"分片执行了，任务项为："+integer);
            }
        }
    }

    public List<Integer> getList(){
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            list.add(i);
        }
        return list;
    }
}
